#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int minMagic(vector<int>& A) {
    int N = A.size();
    int magicCount = 0;
    
    for (int i = 1; i < N; ++i) {
        if (A[i - 1] == 0 && A[i] == 1) {
 
            int j = i - 1;
            while (j >= 0 && A[j] == 0) {
                j--;
            }
            if (j >= 0) {

                A[j]++;
                magicCount++;
                i = j + 1; 
        }
    }
    }
    
    return magicCount;
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    
    int result = minMagic(A);
    cout << result << endl;
    
    return 0;
}
